//Copyright (c) Microsoft Corporation.  All rights reserved.

using System;
using System.Collections.Generic;
using System.Text;

namespace Eas.WebCrawler.Test.Scenario {
    static class UriMap {
        static Dictionary<Uri, Uri> _Map = new Dictionary<Uri, Uri>();
        static object _Lock = new object();
        static void Add(string key, string value) {
            Add(new Uri(key, UriKind.RelativeOrAbsolute), new Uri(value, UriKind.RelativeOrAbsolute));
        }

        public static void Add(Uri key, Uri value) {
            lock (_Lock) {
                if (!_Map.ContainsKey(key))
                    _Map.Add(key, value);
                else
                    _Map[key] = value;
            }
        }

        public static void Clear() {
            lock (_Lock) {
                _Map.Clear();
            }
        }

        public static Uri Get(Uri key) {
            lock (_Lock) {
                if (_Map.ContainsKey(key))
                    return _Map[key];
                else
                    return key;
            }
        }

        public static Uri Get(string key) {
            return Get(new Uri(key, UriKind.RelativeOrAbsolute));
        }

    }
}
